#include "ProgressStopCondition.h"
#include "EvolutionaryAlgorithm.h"
#include "MatrixGraph.h"
#include "Printer.h"

#include <iostream>

ProgressStopCondition::ProgressStopCondition()
	: checkNo(0), bestScore(0.0)
{
}

bool ProgressStopCondition::isNotFulfilled(const EvolutionaryAlgorithm::population_type & actualPopulation)
{
	double bestPopulationScore = 0.0;
	
	for (EvolutionaryAlgorithm::population_type::const_iterator i = actualPopulation.begin(); i != actualPopulation.end(); ++i)
	{
		if (i->containsAllGraphVerts())
		{
			return false;
		}
		double score = i->fitnessValue;
		if (score > bestPopulationScore)
		{
			bestPopulationScore = score;
		}
	}
	++checkNo;
	if (bestPopulationScore > bestScore)
	{
		bestScore = bestPopulationScore;
		checkNo = 0;
	}
    //std::cout << " checkNo gorszego: " << checkNo << " best nO: " << bestScore << std::endl;
	return checkNo <= Configuration::stopChecksNo;
}
